﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    /// <summary>
    /// 登录管理类
    /// </summary>
    class DoLogin
    {
        DataClasses1DataContext ctx = new DataClasses1DataContext();
        /// <summary>
        /// 登录 返回999为管理员登录 返回1为普通用户 返回0为登录失败
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        int Login(string userName, string password)
        {
            try
            {
                var re = 0;
                var a = ctx.T_User.Single(p => p.UserName == userName && p.Password == password && p.Status == 1);
                if (a.Role == 999)//管理员
                {
                    return 999;
                }
                else if (a.Role == 1)//普通用户
                {
                    return 1;
                }
                return re;
            }
            catch
            {

                return 0;
            }
        }
    }
}
